package com.yaopaikeji.controller;

import com.yaopaikeji.constants.Constants;
import com.yaopaikeji.constants.RestResult;
import com.yaopaikeji.constants.ResultsEnum;
import com.yaopaikeji.model.User;
import com.yaopaikeji.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/auth")
public class LoginController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public RestResult<User> login(@RequestBody Map<String,Object> loginInfo){

        String loginId = (String) loginInfo.get(Constants.LOGIN_ID);
        String pass = (String) loginInfo.get(Constants.PASS);

        User user = userService.login(loginId,pass);

        return new RestResult<>(user);

    }


    @GetMapping("/logout")
    public RestResult<String> logout(){

        userService.logout();

        return new RestResult<>("");
    }

}
